@extends('layouts.tankuang')

@section('content')
        <div id="faren">
            <a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_faren()">添加</a>
            <a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="del_faren()">删除</a>
        </div>
        <table id="cailiao_form" title="" class="easyui-datagrid" style="width:100%;height:600px"
               data-options="rownumbers:true,singleSelect:true,pagination:true,pageSize:20,url:'{{url('admin/baoan/cailiao_list',[$id,$uid])}}',method:'get',toolbar:'#faren'">
            <thead>
            <tr>
                <th data-options="field:'name'" width="30%" align="center">文件名</th>
                <th data-options="field:'size'" width="10%" align="center">文件大小</th>
                <th data-options="field:'user_id'" width="20%" align="center">上传人</th>
                <th data-options="field:'created_at'" width="20%" align="center">上传时间</th>
                <th data-options="field:'id',formatter:caozuo" width="20%" align="center">操作</th>
            </tr>
            </thead>
        </table>

        <div id="shangchuan" class="easyui-window" closed="true" title="新增" data-options="iconCls:'icon-save'" style="width:500px;height:300px;padding:10px;"></div>

        <div id="del_faren" class="easyui-dialog" title="注销" closed="true" style="width:400px;height:200px;line-height:100px;text-align:center;font-size:16px;padding:10px">
            您确定要删除该文件？
        </div>
        
        <script>
            function caozuo(value,row,index){
                return '<a href="'+'http://nb.yntosite.com/'+row.pic+'" target="_blank">下载或预览</a>';
            }
            function add_faren(){
                $('#shangchuan').window({
                    title: "添加",
                    href: "{{url('admin/baoan/add_cailiao',[$id,$uid])}}",
                    width:'500',
                    height:'300',
                    minimizable:false,
					top:($(window).height() - 300) * 0.5,
					left:($(window).width() - 500) * 0.5,
                    modal:true,
                    closed: false,
                });
            }
            function del_faren(){
                var row = $('#cailiao_form').datagrid('getSelected');
                if (row) {
                    $('#del_faren').dialog({
                        title: "删除",
                        closed: false,
                        modal:true,
                        buttons: [{
                            text: '确定',
                            iconCls: 'icon-ok',
                            handler: del
                        }, {
                            text: '取消',
                            iconCls: 'icon-cancel',
                            handler: function () {
                                $('#del_faren').dialog('close');
                            }
                        }]
                    });
                } else {
                    $.messager.alert('提示','请选中要编辑的行！');
                }
            }
            function del(){
                $('#del_faren').dialog('close');
                var row = $('#cailiao_form').datagrid('getSelected');
                var url = "{{url('admin/baoan/del_cailiao')}}"+"/"+row.id;
                $.ajax({
                    type: 'get',
                    url: url,
                    success: function(data){
                        if(data.status == 1){
                            $.messager.alert('信息提示',data.msg,'info');
                            var rowIndex = $('#cailiao_form').datagrid('getRowIndex', row);
                            $('#cailiao_form').datagrid('deleteRow', rowIndex);
                        }
                        else{
                            $.messager.alert('信息提示',data.msg,'info');
                        }
                    }
                });
            }
        </script>
@stop